#include<iostream>
#include<pthread.h>
#include<vector>
struct ThreadData{
    std::string _name;
    
    ThreadData(std::string& name):_name(name){}
};
int ticket = 1000;
void* function(void* args){
    ThreadData* dataptr = (ThreadData*)args;
    while(ticket){
        ticket--;
        std::cout<<"线程:"<<dataptr->_name<<"销毁了一张票,"<<"表余额:"<<ticket<<std::endl;
    }
    return nullptr;
}
int main(){
    int num = 5;
    std::vector<pthread_t> tids;
    for(int i=0;i<num;i++){
        pthread_t tid;
        std::string name="thread-"+std::to_string(i);
        ThreadData* data = new ThreadData(name);
        pthread_create(&tid,nullptr,function,(void*)data);
       
        tids.push_back(tid);
    }
    for(int i=0;i<num;i++){
        pthread_join(tids[i],nullptr);
    }
    return 0;
}
